package com.example.signdemo.controllers;

import com.example.core.libs.JSONResult;
import com.example.signdemo.services.IUserSignMService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/m")
public class SignMController {
    @Autowired
    IUserSignMService userSignMService;

    @RequestMapping("/sign")
    public JSONResult sign(@RequestParam long userId) {
        userSignMService.sign(userId);
        return new JSONResult("签到成功");
    }

    @RequestMapping("/againSign")
    public JSONResult againSign(@RequestParam long userId, @RequestParam String day) {
        userSignMService.againSign(userId, day);
        return new JSONResult("补签成功");
    }

    @RequestMapping("/continuousSignCount")
    public JSONResult continuousSignCount(@RequestParam long userId) {
        int count = userSignMService.continuousSignCount(userId);
        return new JSONResult().put("count", count);
    }

    @RequestMapping("/signDays")
    public JSONResult signDays(@RequestParam long userId) {
        long num = userSignMService.signDays(userId);
        return new JSONResult().put("num", num);
    }
}
